home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / programs / in_create.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  14.8 KB  |  426 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)in_create.c    V1.27    8/15/95";
  3. #endif
  4. /*
  5. |    file name in_create.c
  6. |===================================================================
  7. |
  8. |       This programs show how to create input objects
  9. |       programmatically.
  10. |
  11. |       This program creates a Combiner that contains several
  12. |       embedded input objects. The embedded input objects consist
  13. |       of a slider, a text entry field, an object toggle, a color
  14. |       palette, a text menu, and an checklist.
  15. |
  16. |===================================================================
  17. */
  18. #include <windows.h>
  19. /*
  20.  *  DV-Tools header files
  21.  */
  22. #include "std.h"                /* <stdio.h> etc., scalar & macro definitions */
  23. #include "dvstd.h"              /* public types & constants */
  24. #include "dvtools.h"            /* constants used by T routines */
  25. #include "dvGR.h"               /* constants used by window mgt & GR routines */
  26. #include "VOstd.h"              /* constants used by VO & VOob routines */
  27. #include "Tfundecl.h"           /* T routines (screens, drawports & views) */
  28. #include "VOfundecl.h"          /* VO routines (objects) */
  29. #include "VUerfundecl.h"        /* VUer routines (event handling routines) */
  30. #include "VPfundecl.h"          /* VP routines (put info for dgp & vdp) */
  31.  
  32. /* Constants */
  33. #define  DVPATH            (char *)NULL
  34. #define  DISPFORMS_STB     (char *)NULL
  35. #define  DVDEVICE          (char *)NULL
  36. #define  DVCOLORTABLE      (char *)NULL
  37. #define  SCREEN_VIEWPORT   (RECTANGLE *)NULL
  38. #define  TEXTBUFSIZE       80
  39.  
  40. /* Whole world rectangle, (-16384, -16384) to (16383, 16383)*/
  41. LOCAL RECTANGLE whole_world = {XMIN, YMIN, XMAX, YMAX};
  42.  
  43. /* Define buffers for input objects */
  44. char TextValue[TEXTBUFSIZE] = {'H', 'i', 0,};
  45. float SliderValue = 1.0,        /* slider buffer */
  46.   ToggleValue,                  /* object toggle buffer */
  47.   PaletteValue,                 /* color palette buffer */
  48.   MenuValue,                    /* text menu buffer */
  49.   ChecklistValues[8];           /* checklist buffer */
  50.  
  51. /* Define list of pickable items for text menu */
  52. char  *Menu[]=
  53. {
  54.   "DataViews Corp.", "DataViews", "DV-Draw", "DV-Tools", "DV-Play"
  55. };
  56.  
  57. /* Define interaction handlers */
  58. GLOBALREF INHANDLER VNcombiner, VNslider, VNtext, VNtoggle, VNpalette,
  59.   VNmenu, VNchecklist;
  60.  
  61. /* Define list of layout view file names */
  62. char *LayoutNames[]=
  63. {
  64.   "DefSlider.lay",
  65.   "DefText.lay",
  66.   "DefObjTogg.lay",
  67.   "DefPalette.lay",
  68.   "Menu_v5.lay",
  69.   "DefObjCh.lay"
  70.   };
  71.  
  72. /*
  73.  *   MAIN PROGRAM
  74.  */
  75. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, 
  76.                      LPSTR lpCmdLine, int nCmdShow )
  77. {
  78.   INT argc = 0;
  79.   CHAR **argv;
  80.   /*
  81.    *  program arguments
  82.    *    argv[1] - display device (default is DVDEVICE)
  83.    */
  84.  
  85.   /* Define & initialize device name and view filename */
  86.   char *device_name = DVDEVICE; /* default device name */
  87.  
  88.   /* Define display variables */
  89.   OBJECT screen;                /* display device, the window */
  90.   DRAWPORT drawport;            /* how & where to display picture, picture frame */
  91.   VIEW view;                    /* picture representation of the view file */
  92.  
  93.   /* Control loop variables */
  94.   OBJECT location;              /* the event representation */
  95.   int  event_status;            /* how the event handler has used the location 
  96.                                    event */
  97.  
  98.   /* Other variables */
  99.   int Quit = NO;                /* flag to quit program */
  100.   int i;                        /* counter */
  101.  
  102.   /* Input object related variables */
  103.   ATTRIBUTES Attributes;        /* attribute structure */
  104.   VIEW TemplateView;            /* template view */
  105.   OBJECT TemplateDrawing;       /* drawing object of template view */
  106.   OBJECT LLcorner,              /* lower left pt of input obj */
  107.     URcorner,                   /* upper right pt of input obj */
  108.     CombinerInput,              /* combiner input obj */
  109.     CombinerTechnique,          /* combiner input technique obj */
  110.     InputObjects[6],            /* embedded input objects */
  111.     InputTechs[6];              /* embedded input objs technique objs */
  112.   INHANDLER InputHandlers[6];   /* list of interaction handlers */
  113.   VARDESC Vdps[13];             /* variable descriptors for input objs */
  114.  
  115.   /*--------------------
  116.    *  Initialization
  117.    *
  118.    *   TInit:  perform the initialization of DV-Tools
  119.    *           TInit reads your configuration file and any
  120.    *           environment variables or logical names set.
  121.    */
  122.   make_argv(&argc,&argv,GetCommandLine());
  123.   TInit (DVPATH, DISPFORMS_STB);
  124.  
  125.   /*
  126.    *   TscOpenSet: open a device as a screen object using
  127.    *               specified attributes
  128.    *   TscErase:   erase the entire screen in the default
  129.    *               background color
  130.    *
  131.    *   Set exposure block to YES to insure the window
  132.    *   is ready for drawing when TdpDraw is called.
  133.    */
  134.   if (argc > 1)
  135.     device_name = argv[1];
  136.   screen = TscOpenSet (device_name, DVCOLORTABLE,
  137.                        V_X_EXPOSURE_BLOCK, YES,
  138.                        V_ACTIVE_CURSOR, V_END_OF_LIST);
  139.   if (!screen)
  140.     {
  141.       printf ("Must specify device on command line or");
  142.       printf (" in DataViews configuration file.\n");
  143.       S_EXIT (EXIT_ERR);
  144.     }
  145.  
  146.   /*
  147.    *   VOscWinEventMask:  sets the screen's window event mask
  148.    */
  149.   VOscWinEventMask ((ULONG) V_KEYPRESS | V_KEYRELEASE |
  150.                             V_BUTTONPRESS | V_BUTTONRELEASE |
  151.                             V_MOTIONNOTIFY | V_EXPOSE | V_RESIZE,
  152.             (ULONG) 0);
  153.  
  154.   /*
  155.    *   TviCreate:  create a view which will be empty.
  156.    *   TdpCreateStretch: Create a DV-tools window, a drawport
  157.    *                "drawport" is attached to the screen object, "screen"
  158.    *                "view" is the view to be displayed on the screen
  159.    *                "SCREEN_VIEWPORT" specifies the area of the screen
  160.    *               to use to display the drawport
  161.    *                "whole_world" specifies the portion of the view to be
  162.    *                      displayed, here the whole view
  163.    *                The whole view will be stretched to fit in the drawport
  164.    */
  165.   view = TviCreate ();
  166.   drawport = TdpCreateStretch (screen, view,
  167.                                SCREEN_VIEWPORT, &whole_world);
  168.  
  169.   /*
  170.    *   VUerPutKeys:  Sets the key-action bindings
  171.    *             define the left mouse button as the select
  172.    *              keys while the right mouse button will
  173.    *              represent the cancel key.
  174.    */
  175.   VUerPutKeys (SELECT_KEYS, "\001");
  176.   VUerPutKeys (CANCEL_KEYS, "\003");
  177.  
  178.   /*
  179.    *   VOuAtInit:  Sets all attribute fields to EMPTY_FIELD.
  180.    *   VOcoCreate: Create a color or RGB object
  181.    *   VOptCreate: Create a point object
  182.    *
  183.    *   Initialize the attributes structure and fill the fields
  184.    *   representing foreground and background color. Also,
  185.    *   create the control points to be used by the combiner
  186.    *   input object and its embedded input objects
  187.    */
  188.   VOuAtInit (&Attributes);
  189.   Attributes.foreground_color = VOcoCreate (COLOR_NAME, "white");
  190.   Attributes.background_color = VOcoCreate (COLOR_NAME, "black");
  191.   LLcorner = VOptCreate (WORLD_COORDINATES, -14000, -14000, (OBJECT) NULL);
  192.   URcorner = VOptCreate (WORLD_COORDINATES, 14000, 14000, (OBJECT) NULL);
  193.  
  194.   /*
  195.    *   VOinCreate:  Create an input object
  196.    *
  197.    *   Create the embedded input objects (6).
  198.    */
  199.   for (i = 0; i <= 5; i++)
  200.     InputObjects[i] = VOinCreate (LLcorner, URcorner, &Attributes);
  201.  
  202.   /*
  203.    *   VPvdcreate:   Create a variable descriptor
  204.    *   VPvd_drange:  Sets the range in doubles.
  205.    *   VPvddim:      Specifies the dimensions of a variable
  206.    *
  207.    *   Create the variable descriptors for each of the input objects.
  208.    *   The variable descriptors will be bound to program variables.
  209.    */
  210.   Vdps[0] = VPvdcreate ((ADDRESS) & SliderValue, V_F_TYPE);
  211.   VPvd_drange (Vdps[0], 1.0, 2.0);
  212.   Vdps[1] = VPvdcreate ((ADDRESS) TextValue, V_T_TYPE);
  213.   VPvddim (Vdps[1], 1, 1, TEXTBUFSIZE);
  214.   Vdps[2] = VPvdcreate ((ADDRESS) & ToggleValue, V_F_TYPE);
  215.   Vdps[3] = VPvdcreate ((ADDRESS) & PaletteValue, V_F_TYPE);
  216.   Vdps[4] = VPvdcreate ((ADDRESS) & MenuValue, V_F_TYPE);
  217.  
  218.   /*
  219.    *   VOinPutVarList:  Sets the variable descriptor list
  220.    *
  221.    *   Set the vdp list for each of the input objects.
  222.    */
  223.   for (i = 0; i <= 4; i++)
  224.     VOinPutVarList (InputObjects[i], &Vdps[i], 1);
  225.  
  226.   /*
  227.    *  VPvdcreate:      Create a variable descriptor
  228.    *  VOinPutVarList:  Sets the variable descriptor list
  229.    *
  230.    *  Create a variable descriptors for each of the elements
  231.    *  in the checklist.  The variable descriptor will point to
  232.    *  an array element whose value with be 0 or 1.
  233.    */
  234.   for (i = 0; i <= 7; i++)
  235.     Vdps[i + 5] = VPvdcreate ((ADDRESS) & ChecklistValues[i], V_F_TYPE);
  236.   VOinPutVarList (InputObjects[5], &Vdps[5], 8);
  237.  
  238.   /*
  239.    *  VOitCreate:    Create an input technique object
  240.    *  VOinTechnique: Sets the input technique to be used for this
  241.    *              input object.
  242.    *
  243.    *  Load in the layout views which will define the appearance of
  244.    *  the input object. The drawing object of the view is obtained
  245.    *  and attached to the input technique.  The input technique
  246.    *  defines the type of input object based on the interaction
  247.    *  handler and the appearance is defined by the layout file.
  248.    */
  249.   InputHandlers[0] = VNslider;
  250.   InputHandlers[1] = VNtext;
  251.   InputHandlers[2] = VNtoggle;
  252.   InputHandlers[3] = VNpalette;
  253.   InputHandlers[4] = VNmenu;
  254.   InputHandlers[5] = VNchecklist;
  255.   for (i = 0; i <= 5; i++)
  256.     {
  257.       TemplateView = TviLoad (LayoutNames[i]);
  258.       TemplateDrawing = TviGetDrawing (TemplateView);
  259.       InputTechs[i] = VOitCreate (InputHandlers[i], TemplateDrawing);
  260.       VOinTechnique (InputObjects[i], InputTechs[i]);
  261.       TviDestroy (TemplateView);
  262.     }
  263.  
  264.   /*
  265.    *  VOitPutList:  Sets the list of pickable items
  266.    *
  267.    *  The fourth input technique object represents the input
  268.    *  technique for the text menu input object.  The list of
  269.    *  selectable items is set using this routine.
  270.    */
  271.   VOitPutList (InputTechs[4], TEXT_LIST, (ADDRESS) Menu, 5);
  272.  
  273.   /*
  274.    *  Create the combiner input object and its technique object.
  275.    *  Attach the embedded input objects to the technique
  276.    *  and attach the technique to the combiner input object.
  277.    */
  278.   CombinerInput = VOinCreate (LLcorner, URcorner, &Attributes);
  279.   TemplateView = TviLoad ("Combiner.lay");
  280.   CombinerTechnique = VOitCreate (VNcombiner,
  281.                                   TviGetDrawing (TemplateView));
  282.   TviDestroy (TemplateView);
  283.   VOitPutList (CombinerTechnique, OBJECT_LIST, (ADDRESS) InputObjects, 6);
  284.   VOinPutVarList (CombinerInput, Vdps, 13);
  285.   VOinTechnique (CombinerInput, CombinerTechnique);
  286.  
  287.   /*
  288.    *  VOdrObAdd:  Adds an object to the drawing
  289.    *
  290.    *  Add the combiner input object to the view's drawing.
  291.    *  The object will be drawn, updated and redrawn whenever
  292.    *  these actions are performed on the drawport containing
  293.    *  this view.
  294.    */
  295.   VOdrObAdd (TviGetDrawing (view), CombinerInput);
  296.  
  297.   /*
  298.    *  TscErase:  erase the entire screen in the default
  299.    *          background color
  300.    *  TdpDraw:   Draw the contents of a drawport
  301.    *
  302.    *  Erase the screen and draw the drawport.
  303.    */
  304.   TscErase (screen);
  305.   TdpDraw (drawport);
  306.  
  307.   /*--------------------
  308.    *   Control loop
  309.    *
  310.    *   Poll the event queue for window events specified by the
  311.    *   window mask.  Handle each of the events as they happen.
  312.    *   Events occurring within input objects will be handled
  313.    *   through the event request handler VUerHandleLocEvent.
  314.    *   Stop when the user selects "q|Q" or the right mouse button.
  315.    */
  316.   FOREVER
  317.   {
  318.     /*
  319.      *  VOloWinEventPoll:   Poll for the next window event.
  320.      *
  321.      *  VUerHandleLocEvent: Service the event. This routine will check
  322.      *                      if the event is used by any input objects
  323.      *                      that may be in the view.
  324.      */
  325.     location = VOloWinEventPoll (V_WAIT);
  326.     event_status = VUerHandleLocEvent (location);
  327.  
  328.     /*
  329.      * If the return value of VUerHandleLocEvent is INPUT_UNUSED
  330.      * then check for keypress or buttonpress events which
  331.      * represent one of the exit keys.
  332.      */
  333.     if (event_status == INPUT_UNUSED)
  334.       {
  335.         /*
  336.          *  VOloType:  returns the type of event.  These types
  337.          *             match event types specified in VOscWinEventMask.
  338.          */
  339.         switch (VOloType (location))
  340.           {
  341.           case V_EXPOSE:
  342.             /*
  343.              *  VOloRegion:  Returns a rectangle representing the
  344.              *               exposed region on the screen.
  345.              *  TscRedraw:   After erasing, redraws all the drawports
  346.              *               in the screen.
  347.              *  A portion of the window has been exposed and needs
  348.              *  to be redrawn.
  349.              */
  350.             TscRedraw (screen, VOloRegion (location));
  351.             break;
  352.  
  353.           case V_RESIZE:
  354.             /*
  355.              *  TscReset:  Resets all screen drawports after
  356.              *             window resizing
  357.              *  The window size has been changed.
  358.              */
  359.             TscReset (screen);
  360.             break;
  361.  
  362.           case V_KEYPRESS:
  363.             /*
  364.              *  Check key selected.
  365.              *  VOloKeySym:  Returns the key symbol value of the
  366.              *               location object
  367.              *
  368.              *  If the key symbol represents the characters 'q'
  369.              *  or 'Q' then quit the program.
  370.              */
  371.             switch (VOloKeySym (location))
  372.               {
  373.               case 'q':
  374.               case 'Q':
  375.                 Quit = YES;
  376.                 break;
  377.               }
  378.  
  379.           case V_BUTTONPRESS:
  380.             /*
  381.              *  Check button selected.
  382.              *  VOloButton:  Returns the button that was pressed
  383.              *
  384.              *  The right mouse button exits the program.
  385.              */
  386.             switch (VOloButton (location))
  387.               {
  388.               case 3:
  389.                 Quit = YES;
  390.                 break;
  391.  
  392.               default:
  393.                 break;
  394.               }
  395.             break;
  396.  
  397.           case V_MOTIONNOTIFY:
  398.           case V_KEYRELEASE:
  399.           case V_BUTTONRELEASE:
  400.           default:
  401.             break;
  402.           }
  403.       }
  404.  
  405.     /* exit the program */
  406.     if (Quit == YES)
  407.       break;
  408.   }
  409.  
  410.   /*--------------------
  411.    *   Termination
  412.    *
  413.    *   TscErase:          Erase the screen object
  414.    *   TdpDestroy:            Destroy the drawport,
  415.    *   TviDestroy:            Destroy the view, freeing the allocated memory
  416.    *   TscClose:              Closes the screen object
  417.    *   TTerminate:            Perform the clean-up for DV-Tools
  418.    */
  419.   TscErase (screen);
  420.   TdpDestroy (drawport);
  421.   TviDestroy (view);
  422.   TscClose (screen);
  423.   TTerminate ();
  424.   return (EXIT_OK);
  425. }
  426.